package dissertation.extensions.ejbmodule.control;

import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModifiableModelsProvider;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
import dissertation.extensions.ejbmodule.view.ComponentPanel;
import dissertation.services.ejbmodule.EJBModuleService;
import dissertation.services.ejbmodule.IEJBModuleService;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class EJBFrameworkSupportInModuleConfigurable extends FrameworkSupportInModuleConfigurable {

    private IEJBModuleService ejbModuleService;
    private ComponentPanel componentPanel;

    public EJBFrameworkSupportInModuleConfigurable() {
        ejbModuleService = new EJBModuleService();
        componentPanel = new ComponentPanel();
    }

    @Override
    public JComponent createComponent() {
        return componentPanel;
    }

    @NotNull
    @Override
    public CustomLibraryDescription createLibraryDescription() {
        return new EJBLibraryDescription();
    }

    @Override
    public boolean isOnlyLibraryAdded() {
        return true;
    }

    @Override
    public void addSupport(@NotNull Module module, @NotNull ModifiableRootModel modifiableRootModel, @NotNull ModifiableModelsProvider modifiableModelsProvider) {
        ejbModuleService.addEJBSupportToModule(module, componentPanel.getSelectedVersion());
    }
}